//
//  MYNewFeatureCell.m
//  MYChatting
//
//  Created by mac on 16/8/17.
//  Copyright © 2016年 lhf. All rights reserved.
//

#import "MYNewFeatureCell.h"
#import "Masonry.h"

@interface MYNewFeatureCell ()

//@property (nonatomic,weak) UIImageView *iconView;
@property (nonatomic,weak) UIButton *startBtn;

@end

@implementation MYNewFeatureCell

- (void)setIndex:(NSInteger)index{
    _index = index;
    
    UIImageView *iconView = [[UIImageView alloc] init];
    iconView.image = [UIImage imageNamed:[NSString stringWithFormat:@"new_feature_%ld",index + 1]];
    [iconView sizeToFit];
    [self.contentView addSubview:iconView];
    //self.iconView = iconView;
    
    UIButton *startBtn = [[UIButton alloc] init];
    [startBtn setTitle:@"开始体验" forState:UIControlStateNormal];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
    startBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [startBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.contentView addSubview:startBtn];
    [startBtn addTarget:self action:@selector(startBtnClick) forControlEvents:UIControlEventTouchUpInside];
    self.startBtn = startBtn;
    
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
//    if (index ==3) {
//        startBtn.hidden = NO;
////        startBtn.transform = CGAffineTransformMakeScale(0, 0);
////        
////        [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.98 initialSpringVelocity:9.8 options:0 animations:^{
////            startBtn.transform = CGAffineTransformIdentity;
////        } completion:^(BOOL finished) {
////            
////        }];
//        
//    }else{
//        startBtn.hidden = YES;
//    }
    startBtn.hidden = YES;
    
    [startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(self.mas_bottom).offset(-50);
    }];
    
}


- (void)startBtnClick{
    //发布通知
    [[NSNotificationCenter defaultCenter] postNotificationName:MYSwitchRootVCNotification object:nil];
}


- (void)startAnimation{
    self.startBtn.hidden = NO;
    self.startBtn.transform = CGAffineTransformMakeScale(0, 0);
    
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.98 initialSpringVelocity:9.8 options:0 animations:^{
        self.startBtn.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
        
    }];
}

@end
